#include "GribOutput.h"

namespace OCPP
{
	GribOutput::GribOutput()
	{
		setType(Type_Double);
	}

	GribOutput::~GribOutput()
	{

	}

	void GribOutput::insert(VarData varData, float level)
	{
		size_t destSize = _vecDouble.size();
		if (destSize == 0)
		{
			_VolumeExtent.dimX = varData.Nx;
			_VolumeExtent.dimY = varData.Ny;
			_VolumeExtent.xMin = varData.lon1;
			_VolumeExtent.xMax = varData.lon2;
			_VolumeExtent.yMin = varData.lat2;
			_VolumeExtent.yMax = varData.lat1;
			if (_VolumeExtent.yMin > _VolumeExtent.yMax)
			{
				float tmp = _VolumeExtent.yMin;
				_VolumeExtent.yMin = _VolumeExtent.yMax;
				_VolumeExtent.yMax = tmp;
			}
		}
		else
		{
			_VolumeExtent.dimZ++;
		}

		if (_VolumeExtent.zMin > level) _VolumeExtent.zMin = level;
		if (_VolumeExtent.zMax < level) _VolumeExtent.zMax = level;

		auto& srcDv = varData.dv;
		size_t srcSize = srcDv.size();


		_vecDouble.resize(destSize + srcSize);
		memcpy(&_vecDouble[destSize], &srcDv[0], srcSize * sizeof(double));
	}
}